package com.dshore.messagecenter.controller.statistics;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dshore.messagecenter.service.statistics.QueuePropertyService;
/**
 * 队列性能控制类
 * @author panyi 
 */
@Controller
@RequestMapping("/index")
public class QueuePropertyController {
	
	@Autowired
	private QueuePropertyService qpService;
	
	/**
	 * 队列性能页面
	 * @return
	 */
	@RequestMapping("/queueProperty")
	public String tomessageFlow() {
		return "statistics/queueProperty";
	}
	
	/**
	 * ---横坐标为时间---查询本日的消息发送延迟
	 * @return
	 */
	@RequestMapping("/getTodayDelayByTime")
	@ResponseBody
	public Map<Object,Object> getTodayDelayByTime() {
		Map<Object,Object> m=qpService.getTodayDelayByTime();
		for(int i=0;i<=9;i++) {
			if(!m.containsKey("0"+i)) {
				m.put("0"+i, 0);
			}
		}
		for(int i=10;i<=24;i++) {
			if(!m.containsKey(i)) {
				m.put(i, 0);
			}
		}
		return m;
	}
	
	/**
	 * ---横坐标为主题队列---查询该主题队列在当日的总延迟
	 * @return
	 */
	@RequestMapping("/getTodayDelayByTopic")
	@ResponseBody
	public List<List>getTodayDelayByTopic(){
		List<List> list=qpService.getTodayDelayByTopic();
		List topicLi=list.get(0);
		for(int i=0;i<10;i++) {
			if(topicLi.size()==i) {
				for(int j=10-i;j>0;j--) {
					topicLi.add("主题队列待创建");
				}
			}
		}
		List messageLi=list.get(1);
		for(int i=0;i<10;i++) {
			if(messageLi.size()==i) {
				for(int j=10-i;j>0;j--) {
					messageLi.add(0);
				}
			}
		}
		List<List> li=new ArrayList<List>();
		li.add(topicLi);
		li.add(messageLi);
		return li;
	}
	
	/**
	 * ---横坐标为时间---根据下拉框中option标签的id来查询本日(53)的队列延迟数据
	 * @return
	 */
	@RequestMapping("/getTodayDelayByTimeByOption")
	@ResponseBody
	public Map<Object, Object> getTodayDelayByTimeByOption(String id) {
		Map<Object, Object> m=getTodayDelayByTime();//调用
		return m;
	}
	
	/**
	 * 根据主题队列---根据下拉框中option标签的id来查询本日(id53)的队列延迟数据
	 * @param id
	 * @return
	 */
	@RequestMapping("/getTodayDelayByTopicByOption")
	@ResponseBody
	public List<List> getTodayDelayByTopicByOption(String id) {
		 List<List>list=getTodayDelayByTopic();//调用
		 return list;
	}
	
	/**
	 * 根据时间---根据下拉框中option标签的id来查询近7日的队列延迟
	 * @param id
	 * @return
	 */
	@RequestMapping("/getWeekDelayByTimeByOption")
	@ResponseBody
	public List<List<Object>>getWeekDelayByTimeByOption(String id) {
		List<Map<String, Object>> list=qpService.getWeekDelayByTimeByOption(id);
		List<Object>qiriqi=new ArrayList<>();
		List<Object>qirizhi=new ArrayList<>();
		List<List<Object>>li = new ArrayList<List<Object>>() ;
		for (Map<String, Object> map : list) {
			Collection<Object> a=map.values();
			Object[] al=a.toArray();
			qiriqi.add(al[0]);
			qirizhi.add(al[1]);
		}
		li.add(qiriqi);
		li.add(qirizhi);
		return li;
	}
	
	/**
	 * 根据主题---根据下拉框中option标签的id来查询近7日延迟数据
	 * @param id
	 * @return
	 */
	@RequestMapping("/getWeekDelayByTopicByOption")
	@ResponseBody
	public List<List> getWeekDelayByTopicByOption(String id) {
		List<List> list=qpService.getWeekDelayByTopicByOption(id);
		return list;
	}
	
	/**
	 * 根据时间---根据下拉框中option标签的id来查询近30日的消息流量数据
	 * @param id
	 * @return
	 */
	@RequestMapping("/getMonthDelayByTimeByOption")
	@ResponseBody
	public List<List<Object>> getMonthDelayByTimeByOption(String id) {
		List<Map<String, Object>> list=qpService.getMonthDelayByTimeByOption(id);
		List<Object>qiriqi=new ArrayList<>();
		List<Object>qirizhi=new ArrayList<>();
		List<List<Object>>li = new ArrayList<List<Object>>() ;
		for (Map<String, Object> map : list) {
			Collection<Object> a=map.values();
			Object[] al=a.toArray();
			qiriqi.add(al[0]);
			qirizhi.add(al[1]);
		}
		li.add(qiriqi);
		li.add(qirizhi);
		return li;
	}
	
	/**
	 * 根据主题---根据下拉框中option标签的id来查询近30日(id55)消息流量数据
	 * @param id
	 * @return
	 */
	@RequestMapping("/getMonthDelayByTopicByOption")
	@ResponseBody
	public List<List>getMonthDelayByTopicByOption(String id) {
		List<List> list=qpService.getMonthDelayByTopicByOption(id);
		return list;
	}
}
